package main

import (
	"net"
	"log"
	"bufio"
	"fmt"
	"time"
	"strings"
)

func main() {
	listener, err := net.Listen("tcp",":8000")
	if err!=nil {
		log.Fatal(err)
	}

	for {
		conn, err := listener.Accept()
		if err!=nil {
			log.Print(err)
		}
		go handleConn(conn)
	}
}

func handleConn(conn net.Conn) {
	defer conn.Close()
	rd := bufio.NewReader(conn)
	for {
		line, err := rd.ReadString('\n')
		if err!=nil {
			log.Print(err)
			break
		}
		go echo(conn, line)
	}
}

func echo(conn net.Conn, text string) {
	delay:=time.Second

	fmt.Fprint(conn, "\t", strings.ToUpper(text))

	time.Sleep(delay)
	fmt.Fprint(conn, "\t", text)

	time.Sleep(delay)
	fmt.Fprint(conn, "\t", strings.ToLower(text))
	
}